//
//  InstallationListModel.swift
//  ezyform
//
//  Created by MoennigQ on 12/12/2016.
//  Copyright © 2016 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import HandyJSON

protocol SearchListModelProtocal {
    
}

struct InstallationListModel: HandyJSON,SearchListModelProtocal {
    
    var pvd_id : Int64 = 0
    var gwt_id : String = ""
    //Scheduled,Installing, Installed, Unqualified
    var status: String = ""
    var solar_water_heater: Bool = false//为 true 时是 swh , 为 false 时是  solar
    //Owner's full name
    var full_name : String = ""
    var company: String = ""
    
    //Owner's address
    var full_install_address : String = ""
    var special_address: String = ""
    //优先显示specail address
    var final_install_address: String {
        if special_address == "" {
            return full_install_address
        }else{
            return special_address
        }
    }
    var install_date: String = ""
    var scheduler_time: String = ""
    var reference: String = ""
    
    var po_reference: String = ""
    
    var completion_ratio: Double = 0
    
    var installation_type: String = ""
    var heater_installation_type: String = ""
    //inverter number total
    var inverter_number_count: Int = 0
    //inverter finish count
    var inverter_number_finished_count: Int = 0
    //panel number total
    var panel_number_count: Int = 0//被web处理老版本用了（panel和inverter 的合并），用于Installation list cell中扫描图片是否完成的判断
    //finished count
    var panel_number_finished_count: Int = 0//被web处理老版本用了（panel和inverter 的合并），用于Installation list cell中扫描图片是否完成的判断，如果panel或inverter完成数量大于等于计划数量，那完成数量就等于计划数量
    //required checklist count
    var require_checklist_count: Int = 0
    //finished equired checklist count
    var require_checklist_finished_count: Int = 0
    //finished signatures
    var signature_finished_count: Int = 0
    //required finished signatures
    var require_signature_count: Int = 0
    //if local data is not uploaded
    var localDataFlag: Bool = false
    //panel number total
    var new_panel_number_count: Int = 0//从3.5.8版本开始，这个才是真正的panel number的数据
    //finished count
    var new_panel_number_finished_count: Int = 0 //从3.5.8版本开始，这个才是真正的panel number的finished数据
    // is_new_stc_form 为 true 表示安装日期是2022-04-01以后的job
    var is_new_stc_form: Bool = false
    var first_time_install: Bool = false
    var pick_up_required: Bool = false
    var rated_output: String = ""
    var require_ces_count: Int = 0
    var require_ces_finished_count: Int = 0
    //MARK: - 是否全部完成
    var allDone: Bool {
        if barcodeFinishCnt >= barcodePlantCnt && checklistFinishCnt >= checklistPlantCnt && signatureFinishCnt >= signaturePlantCnt{
            return true
        }else{
            return false
        }
    }
    //MARK: - 已经完成的checklist数量,除去CES
    var checklistFinishCnt: Int {
        return require_checklist_finished_count
    }
    //MARK: - 计划完成的checklist数量,除去CES
    var checklistPlantCnt: Int {
        return require_checklist_count
    }
    //MARK: - 已经完成的签名数量
    var signatureFinishCnt: Int {
        signature_finished_count
    }
    //MARK: - 计划完成的barcode数量
    var signaturePlantCnt: Int {
        require_signature_count
    }
    //MARK: - CES已经完成的签名数量
    var cesFileFinishCnt: Int {
        return require_ces_finished_count
    }
    //MARK: - 计划完成的barcode数量
    var cesFilePlantCnt: Int {
        return require_ces_count
    }
    //MARK: - 已经完成的barcode数量
    var barcodeFinishCnt: Int {
        if self.solar_water_heater {
            return new_panel_number_finished_count
        }else{
            if self.is_new_stc_form {//2022-04-01之后安装新Job
                return (new_panel_number_finished_count) + (inverter_number_finished_count)
            }else{//2022-04-01之签安装Job，只处理Panel
                return (new_panel_number_finished_count)
            }
        }
        
    }
    //MARK: - 计划完成的barcode数量
    var barcodePlantCnt: Int {
        if self.solar_water_heater {
            return new_panel_number_count
        }else{
            if self.is_new_stc_form {//2022-04-01之后安装新Job
                return (new_panel_number_count ) + (inverter_number_count)
            }else{//2022-04-01之签安装Job，只处理Panel
                return (new_panel_number_count )
            }
        }
    }
    var location: LocationModel = LocationModel()
    
}
